const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const Uglifyjs = require("uglifyjs-webpack-plugin");

module.exports = {
    mode:"production",  // development production
    entry:{
        "setting":"./src/setting/base/Base.js",  //基础设置
        "award-setting":"./src/setting/award/Award.js",  //奖品设置
        "goods":"./src/goods/list/List.js",  //商品列表
        "edit-goods":"./src/goods/edit/Edit.js",  //商品编辑
        "member":"./src/member/list/List.js",  //会员列表
        "order":"./src/order/list/List.js",  //订单列表
        "plugin":"./src/plugin/list/List.js" //插件列表
    },
    output:{
        path:path.dirname(__dirname)+'/kuyuan_fm/dist/web/',
        filename:'[name].js',
        publicPath:'../addons/kuyuan_fm/dist/web/'
    },
    plugins:[
        new CleanWebpackPlugin(),
        new ExtractTextPlugin("[name].css"),
        new Uglifyjs({
            test:/\.js/,
            uglifyOptions:{
                ecma:6
            },
            sourceMap:true
        })
    ],
    module:{
        rules:[
            {
                test:/\.(png|jpeg|jpg|gif|svg|eot|ttf|woff|woff2)$/,
                use:{
                    loader:'file-loader',
                    options:{
                        name:'image/[name]-[hash:6].[ext]'
                    }
                }
            },
            {
                test:/\.less$/i,
                use:ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use:[
                            {
                                loader:"css-loader"
                            },
                            {
                                loader:"less-loader",
                                options: {
                                    minimize: true
                                },
                            }
                        ],
                        publicPath:"./"
                })
            }
        ]
    },
    resolve:{
        alias:{
            'vue':'vue/dist/vue.common.js'
        }
    },
    optimization:{
        splitChunks:{
            name:"common",
            chunks:"initial"
        },
    }
}